#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :forin.py
# @Time      :2021/2/25 22:04
# @Author    :Letquit
"""
文件说明：循环

"""
# for...in循环，依次把list或tuple中的每个元素迭代出来
names = ['Michael', 'Bob', 'Tracy']
for name in names:
    print(name)
# for x in ...循环就是把每个元素代入变量x，然后执行缩进块的语句
sum = 0
for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
    sum = sum + x
print(sum)
# Python提供一个range()函数，可以生成一个整数序列，再通过list()函数可以转换为list
print(list(range(5)))
for x in range(101):
    sum = sum + x
print(sum)
# 第二种循环是while循环，只要条件满足，就不断循环，条件不满足时退出循环
sum = 0
n = 99
# 在循环内部变量n不断自减，直到变为-1时，不再满足while条件，循环退出
while n > 0:
    sum = sum + n
    n = n - 2
print(sum)
L = ['Bart', 'Lisa', 'Adam']
for l in L:
    print('Hello, %s!' % l)







if __name__ == "__main__":
    run_code = 0
